import {Component, EventEmitter,Input, OnInit, Output} from "@angular/core";
import {NzNotificationService, NzModalService} from "ng-zorro-antd";
import {HttpServcie} from "../../../service/http.service";
import {PointDefendBean} from "../bean/pointDefendBean";


@Component({
  selector: "point-defend-add",
  templateUrl: "point-defend-add.html",
  styleUrls: ["point-defend-add.scss"]
})
export class PointDefendAdd implements OnInit {


  // 定义父子传值事件
  @Output("outPut")
  public outPut = new EventEmitter();
  // 定义对象
  public pointDefendBean:PointDefendBean = new PointDefendBean();

  // 定义当前登录人的信息
  public user:any;


  constructor(
    private _notification: NzNotificationService,
    private httpServcie: HttpServcie
  ) {
  }

  ngOnInit() {
    this.user = JSON.parse(window.localStorage.getItem("user"));
    console.log(this.user);
  }

  // 添加方法
  submitForm($event) {

    if(this.pointDefendBean.operationType ==undefined ){
      this._notification.create("warning", "警告提示", "操作类型不能为空！");
      return false;
    }

    if(this.pointDefendBean.operationRole ==undefined ){
      this._notification.create("warning", "警告提示", "操作角色不能为空！");
      return false;
    }

    if(this.pointDefendBean.operationContent ==undefined ){
      this._notification.create("warning", "警告提示", "操作内容不能为空！");
      return false;
    }

    if(this.pointDefendBean.identification ==undefined ){
      this._notification.create("warning", "警告提示", "唯一标识不能为空！");
      return false;
    }

    if(this.pointDefendBean.mark ==undefined ){
      this._notification.create("warning", "警告提示", "分数不能为空！");
      return false;
    }

    // 创建人
    this.pointDefendBean.createBy = JSON.parse(window.localStorage.getItem("user")).userName;

    this.httpServcie.insertPointDefend(this.pointDefendBean).subscribe(data => {
        if (data.status == 200) {
          this._notification.create("success", "成功", "新增成功！");
          this.outPut.emit($event);
        } else {
          this._notification.create("error", "错误提示", data.message);
        }
      },
      error => {
        this._notification.create("error", "错误提示", "删除失败！");
      }
    )
  }



}
